package com.kly.order.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.google.common.collect.Maps;
import com.kly.order.db.dao.MemberDao;
import com.kly.order.db.entity.MemberEntity;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* User: 11437
* Date: 2023-05-31
* Time: 17:06:59.458
*/

@Repository
public class MemberDaoImpl extends AbstractBaseMapper<MemberEntity> implements MemberDao {

    @Override
    public MemberEntity getMembers(String userCode, Date date) {
        Map<String, Object> params = new HashMap<>();
        params.put("userCode", userCode);
        params.put("deleted", 0);
        params.put("date", new Date());
        return this.getSqlSession().selectOne(this.getStatement("getMembers"), params);
    }

    @Override
    public List<MemberEntity> selectByUser(Map<String, Object> params) {
        return this.getSqlSession().selectList(this.getStatement("selectByUser"), params);
    }

    @Override
    public List<MemberEntity> selectMembers(String userCode) {
        return this.getSqlSession().selectList(this.getStatement("selectMembers"), userCode);
    }

    @Override
    public Integer ifMember(Map<String, Object> params) {
        return (Integer)this.getSqlSession().selectOne(this.getStatement("ifMember"), params);
    }

    @Override
    public Boolean ifMember(String userCode) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("userCode", userCode);
        params.put("deleted", 0);
        params.put("date", new Date());
        Integer isMember = this.getSqlSession().selectOne(this.getStatement("ifMember"), params);
        return isMember > 0;
    }
}